package com.agy.filemanager.controller;

import com.agy.filemanager.common.StringUtils;
import com.agy.filemanager.common.TreeUtil;
import com.agy.filemanager.entity.DcDocProjectStep;
import com.agy.filemanager.entity.TreeModel;
import com.agy.filemanager.service.ProStageService;
import com.agy.filemanager.toolClass.Result;
import com.agy.filemanager.toolClass.ResultUtil;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 项目阶段Controller
 */
@RestController
@RequestMapping("pro/stage")
public class ProStageController {

    @Autowired
    private ProStageService proStageService;

    /**
     * 项目大类和项目分类树
     * @return
     */
    @GetMapping("selectTree")
    public Result selectTree(){
        List<TreeModel> treeList = TreeUtil.getTree(this.proStageService.selectTree());
        return ResultUtil.success(treeList);
    }

    /**
     * 查询项目阶段表
     * @param pageSize
     * @param pageNum
     * @param id
     * @return
     */
    @GetMapping("selectTable")
    public Map<String,Object> selectTable(int pageSize,int pageNum,String id,String name){
        Page list = this.proStageService.selectTable(pageSize,pageNum,id,name);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("total",list.getTotal());
        map.put("rows",list.getResult());
        return map;
    }

    /**
     * 根据阶段类型ID查询项目阶段信息
     * @param stepTypeId  阶段类型ID
     * @return
     */
    @GetMapping("selectProjectStepByStepTypeId")
    public Result selectProjectStepByStepTypeId(String stepTypeId){
        List<TreeModel> list = this.proStageService.selectProjectStepByStepTypeId(stepTypeId);
        return ResultUtil.success(list,"成功");
    }

    /**
     * 保存项目阶段
     * @param dcDocProjectStep
     * @return
     */
    @PostMapping("insertStage")
    public Result insertStage(@RequestBody DcDocProjectStep dcDocProjectStep){
        this.proStageService.insertStage(dcDocProjectStep);
        return ResultUtil.success("保存成功");
    }

    /**
     * 删除项目阶段
     * @param id
     * @return
     */
    @DeleteMapping("deleteStage")
    public Result deleteStage(String id){
        this.proStageService.deleteStage(id);
        return ResultUtil.success("删除成功");
    }
}
